package com.lb.shopguide.im.session.viewholder;

import android.widget.ImageView;
import android.widget.TextView;

import com.lb.shopguide.R;
import com.lb.shopguide.entity.goods.GoodsInChatBean;
import com.lb.shopguide.event.guide.OnMessageGoodsClickEvent;
import com.lb.shopguide.im.session.extension.GoodsAttachment;
import com.lb.shopguide.util.pic.ImageLoaderUtils;
import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by kang on 2017/6/6.
 */

public class MsgViewHolderGoods extends MsgViewHolderBase {
    private ImageView ivGoods;
    private TextView tvGoodsName;
    private TextView tvPrice;
    private String goodsCode;

    public MsgViewHolderGoods(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }

    @Override
    protected int getContentResId() {
        return R.layout.nim_message_item_goods;
    }

    @Override
    protected void inflateContentView() {
        ivGoods = view.findViewById(R.id.iv_goods);
        tvGoodsName = view.findViewById(R.id.tv_goods_name);
        tvPrice = view.findViewById(R.id.tv_price);
    }

    @Override
    protected void bindContentView() {
        GoodsAttachment attachment = (GoodsAttachment) message.getAttachment();
        GoodsInChatBean goodsBean = attachment.getGoodsInOrder();
        goodsCode = goodsBean.getProductCode();
        ImageLoaderUtils.displayRound(context, ivGoods, goodsBean.getProductPicUrl(), 4);
        tvGoodsName.setText(goodsBean.getProductName());
        tvPrice.setText("￥" + goodsBean.getPrice());
    }

    @Override
    protected void onItemClick() {
        EventBus.getDefault().post(new OnMessageGoodsClickEvent(goodsCode));
    }

    @Override
    protected int rightBackground() {
        return com.netease.nim.uikit.R.drawable.iv_mine_send_goods;
    }
}
